<?php
$this->Html->addCrumb('Services', '/services');
$this->Html->addCrumb($serviceInfo['Service']['name'],array('controller'=>'companies','action'=>'company_service',$serviceInfo['Service']['id']));
$this->Html->addCrumb($adInfo['Company']['name']);
$photoPresent = false;
?>
<?php
//css
echo $this->Html->css(array('jquery.cluetip','prettyPhoto-min','tws-framework'), false);
//js
echo $this->Html->script(array('jquery.hoverIntent.min','plugins/jquery.cluetip','plugins/jquery.prettyPhoto-min'), false);

$this->Html->scriptStart(array('inline' => false));
echo '
      $(function(){
        $("img.product").each(function(index, value) {
          $(this).attr("title",$(this).attr("rel"));
        });
        $("img.product").cluetip({attribute : "rel",cluetipClass: "islevow", splitTitle : "|",  positionBy : "fixed" , leftOffset : 12, rightOffset : 0,
          hoverIntent: {
            sensitivity:  10,
            interval: 200,
            timeout: 0
          }
        });

        $("a.coupon").each(function(index, value) {
          $(this).attr("title",$(this).attr("rel"));
        });
        $("a.coupon").cluetip({attribute : "rel",cluetipClass: "islevow", splitTitle : "|",  positionBy : "fixed" , leftOffset : 12, rightOffset : 0,
          hoverIntent: {
            sensitivity:  10,
            interval: 200,
            timeout: 0
          }, clickThrough : true
        });

      var tag = document.createElement("script");
      tag.src = "//www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName("script")[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

      var player;
      function onYouTubeIframeAPIReady() {
        player = new YT.Player("player");
      }
      function onPlayerReady(event) {
        event.target.playVideo();
      }

      $("a[rel^=\'photo\']").prettyPhoto({theme: \'dark_rounded\', social_tools:false, deeplinking : false});

      });
       ';
$this->Html->scriptEnd();
?>
<div class="row-fluid">
  <div id="adPhotoContainer" class="span7">

    <div id="adMultiplePhotoSection" class="row-fluid">
      <div class="span12">
      <?php if(sizeof($adInfo['AdPhotos'])>0 ){$photoPresent = true;}
      foreach($adInfo['AdPhotos'] as $adPhoto) { ?>      
      <?php /*<div class="ad_photo"><?php echo $this->Html->image($adPhoto['image_path'], array('alt' => 'Product','title'=>'Product','class'=>'center product', 'rel'=>$adPhoto['title'].'|'.$adPhoto['description']))?></div>*/ ?>
      <div class="row-fluid">
       <div class="span12">
      <div class="ad_photo span12"><?php echo $this->Html->image($adPhoto['image_path'], array('alt' => $adInfo['Company']['name'],'title'=>$adPhoto['title'],'class'=>'center logo', 'rel'=>$adInfo['Company']['name'].'|'.$adPhoto['title']));?></div>
       </div>
      </div>
       <div class="row-fluid">
      <div id="adPhotoTextSection span12">
        <div class="ad_photo_text_title">
          <p><?php echo $adPhoto['title']?></p>
        </div>
        <div class="ad_photo_text">
          <p><?php echo $adPhoto['description']?></p>
        </div>
      </div>
      </div>        
      <?php } ?>

      </div>
    </div>
    <?php 
    if(!$photoPresent) { ?>
      <div class="row-fluid">
        <div class="ad_photo span12"><?php echo $this->Html->image('large_ad_stock.jpg', array('alt' => 'Ad','title'=>'Ad', 'class'=>'center logo'))?></div>
      </div>
    <?php } ?>
   

    <?php if (!empty($youtubeId)) { ?>
    <div class="row-fluid" style="z-index: -10;">
      <div class="span12">
          <iframe id="player" type="text/html" width="600" height="445"
          src="http://www.youtube.com/embed/<?php echo $youtubeId;?>?enablejsapi=1"
          frameborder="0"></iframe>
      </div>
    </div>
    <?php } ?>
    
    <?php //Checking for Photo Albums
    if (!empty($albums)) { ?>

    <div class="row-fluid" style="margin-top:30px;"><div class="span12">Check out these albums that were created by <?php echo $adInfo['Company']['name'];?></div></div>
      <?php
      $count = 0;
      echo '<div class="row-fluid">';
      foreach ($albums as $rec) {
        
        echo '<div class="span6">';
        echo '<div class="photoAlbum">';
        $picCount = 0;
        foreach ($rec['Photo'] as $photo) {
          if ($picCount === 0) {
            echo '<a href="' . Configure::read('App.pathPrefix') . '/app/webroot/img/' . $photo['image_path'] . '" class="firstPic" rel="photo[pp_gal' . $count . ']" title="' . $photo['caption'] . '">' . $this->Html->image($photo['image_path'], array("alt" => $rec['Album']['name'], "title" => "Click to view this album")) . '</a>';
          } else {
            echo '<a href="' . Configure::read('App.pathPrefix') . '/app/webroot/img/' . $photo['image_path'] . '" rel="photo[pp_gal' . $count . ']" title="' . $photo['caption'] . '">' . $this->Html->image($photo['image_thumb_path'], array("alt" => $rec['Album']['name'])) . '</a>';
          }
          $picCount++;
        }
        $lastUpdated = new DateTime($rec['Album']['modified']);
        echo '<div class="photoAlbumTitle"><span class="albumTitleText">' . $rec['Album']['name'] . '</span><br/><span>Last updated: ' . $lastUpdated->format("m/d/Y") . '</span></div>';
        echo '</div>';
        $count++;
        echo '</div>';
        if ($count ==2) {
          break;
        }
      }
      echo '</div>';
      echo $this->Html->link("View all the albums created by ".$adInfo['Company']['name'],array("controller"=>"albums","action"=>"index",$albums[0]['Category']['id']));
    }
    ?>
    </div> <!--End #adPhotoContainer -->

    <div id="adTextSection" class="span5">
      <div class="ad_title">
        <?php echo $adInfo['Company']['name'];?>
      </div>
      <div class="ad_description">

        <?php echo nl2br($adInfo['Company']['description']);?>

      </div>
      <?php
       if (!empty($adInfo['Company']['image_path'])) {
              echo '<p>' . $this->Html->image($adInfo['Company']['image_path'], array('alt' => $adInfo['Company'] ['name'],'class'=>'logo')) . '</p>';
            }
      ?>

      <div class="ad_contact_information">
        <?php if(!empty($adInfo['Company']['address'])) {?> <p><?php echo $adInfo['Company']['address']; ?></p> <?php } ?>
        <?php if (!empty($adInfo['Company']['phone'])) {?> <p><span class="contactMethod">P.</span><span class="contactMethodValue"> <a href="tel:<?php echo $adInfo['Company']['phone'];?>" class="contact"><?php echo $adInfo['Company']['phone'];?></a> </span></p> <?php } ?>
        <?php if (!empty($adInfo['Company']['phone_additional'])) {?> <p><span class="contactMethod">P.</span><span class="contactMethodValue"> <a href="tel:<?php echo $adInfo['Company']['phone_additional'];?>" class="contact"><?php echo $adInfo['Company']['phone_additional'];?></a> </span></p> <?php } ?>
        <?php if (!empty($adInfo['Company']['fax'])) {?> <p><span class="contactMethod">F.</span><span class="contactMethodValue"> <a href="tel:<?php echo $adInfo['Company']['fax'];?>" class="contact"><?php echo $adInfo['Company']['fax'];?></a> </span></p> <?php } ?>
        <?php if (!empty($adInfo['Company']['email'])) {?> <p><span class="contactMethod">E.</span><span class="contactMethodValue"> <a href="mailto:<?php echo $adInfo['Company']['email'];?>" class="contact"><?php echo $adInfo['Company']['email'];?></a> </span></p> <?php } ?>
        <?php if (!empty($adInfo['Company']['url'])) {?> <p><span class="contactMethod">W.</span><span class="contactMethodValue"> <a href="<?php echo $adInfo['Company']['url'];?>"  class="contact" target="_blank"><?php echo $adInfo['Company']['url'];?></a> </span></p> <?php } ?>
      </div>

      <?php if(!empty($adInfo['Company']['facebook_url']) || !empty($adInfo['Company']['twitter_url']) || !empty($adInfo['Company']['pinterest_url']) ) { ?>
      <div id="socialNetworkingLinks">               
        <?php if(!empty($adInfo['Company']['pinterest_url'])) { ?><a href="<?php echo $adInfo['Company']['pinterest_url'];?>" target="new"><?php echo $this->Html->image('pinterest-logo.png', array('alt' => 'Follow us on pinterest','title'=>'Follow us on pinterest', 'class'=>'social'))?></a> <?php } ?>
        <?php if(!empty($adInfo['Company']['twitter_url'])) { ?><a href="<?php echo $adInfo['Company']['twitter_url'];?>" target="new"><?php echo $this->Html->image('twitter_icon_small.png', array('alt' => 'Follow us on twitter','title'=>'Follow us on twitter', 'class'=>'social'))?></a> <?php } ?>
        <?php if(!empty($adInfo['Company']['facebook_url'])) { ?><a href="<?php echo $adInfo['Company']['facebook_url'];?>" target="new"><?php echo $this->Html->image('facebook_icon_small.png', array('alt' => 'Like us on facebook','title'=>'Like us on facebook', 'class'=>'social'))?></a> <?php } ?>
      </div>
      <?php } ?>

     <?php if (!empty($adInfo['Company']['url'])) { ?>

      <div class="ad_link">
        <p><a href="#" target="_blank">More information here...</a>
        </p>
      </div>
      <?php } ?>

     <?php if (!empty($couponInfo)) { ?>

      <div class="company_coupons">
        <?php echo $this->Html->image('printable_coupons.png', array('alt' => 'Printable Coupons', 'title' => 'Printable Coupons', 'style' => 'border:0;')) ?>
        <ul>
        <?php foreach ($couponInfo as $coupon) {
          $couponUrl = $this->Html->url(array("action"=>"view", "controller"=>"coupons", $coupon['Coupon']['id']));
          if (!empty($coupon['Coupon']['url'])){$couponUrl =$coupon['Coupon']['url']; }
          $validStartDate = new DateTime($coupon['Coupon']['valid_start_date']);
          $validEndDate = new DateTime($coupon['Coupon']['valid_end_date']);
          ?>
          <li><a href="<?php echo $couponUrl;?>" rel="<?php echo $coupon['Coupon']['title'].'|'.$coupon['Coupon']['description'];?>" class="coupon" target="new"><?php echo $coupon['Coupon']['title'];?></a> <span class="couponDateRange">(Valid <?php echo $validStartDate->format('jS M Y').' through '.$validEndDate->format('jS M Y');?>)</span></li>
        <?php } ?>
        </ul>
      </div>
      <?php } ?>

    </div>

</div>